script_enemy_main{

let angle=0;
let speed=0;
let phase=0;
let round=0;

let character="Sayuri";
let cutin=character;
let dispelled=0;
let spellcards=1;
let spellcardnumber=77;
let damagerate=10;
let outfit=1;
outfit=(128*outfit)-128;
let usespell=0;
let bgfade=0;
let frame=0;
let time=0;
let miny=GetClipMinY; let maxy=GetClipMaxY; let minx=GetClipMinX; let maxx=GetClipMaxX;
let cx=GetCenterX; let cy=GetCenterY;

let SEcharge1=("\script\SoundEffects\charge1.wav");
let SEshotm8=("\script\SoundEffects\shotm8.wav");
let SEmagics1=("\script\SoundEffects\magics1.wav");

let BG1=("\script\Images\BackgroundLayers\Sayuri2a.png");
let GRboss=("\script\Images\CharacterSprites\"~character~".png");

#include_function "script/Functions/SetSpellcardCommonData.txt";
#include_function "script/Functions/SpellcardNameLoad.txt";
#include_function "script/Functions/HealthBarLoad.txt";
#include_function "script/Functions/CutInLoad.txt";

@Initialize{
	LoadUserShotData("script\shots\Shots"~character~"1.txt");

	LoadSE("\script\SoundEffects\charge1.wav");
	LoadSE("\script\SoundEffects\shotm8.wav");
	LoadSE("\script\SoundEffects\magics1.wav");
	
	LoadGraphic("\script\Images\BackgroundLayers\Sayuri2a.png");
	LoadGraphic("\script\Images\CharacterSprites\"~character~".png");

	SetScore(2500000);
	SetLife(900);
	SetTimer(80);
	SetInvincibility(120);
	SetDamageRate(10,10);
	SetEnemyMarker(true);
	MagicCircle(true);
	#include_function "script/Functions/Focus.txt";
	Focus(character);
	SetEffectForZeroLife(60,100,1);
	SetMovePosition02(cx,miny+100,50);
	SetDurableSpellCard;
}
	
@MainLoop{

SetCollisionA(GetX,GetY,16);
SetCollisionB(GetX,GetY,16);
SetShotAutoDeleteClip(150,150,150,150);

Weakness(character);
#include_function "script/Functions/Weakness.txt";
if(GetCommonData("BombOn")==0){ damagerate=10; }
if(GetCommonData("BombOn")==1){ damagerate=0; }
SetDamageRate(damagerate*weaken,damagerate*weaken);

let difficulty="";
if(GetCommonDataDefault("Difficulty",2)==1){ difficulty="Easy"; }
if(GetCommonDataDefault("Difficulty",2)==2){ difficulty="Normal"; }
if(GetCommonDataDefault("Difficulty",2)==3){ difficulty="Hard"; }
if(GetCommonDataDefault("Difficulty",2)==4){ difficulty="Lunatic"; }

SpellcardName("Equivocation [Sucker Effect]",spellcardnumber); 
HealthBar();
Portrait(cutin,1);


if(time==60){
let ypos=miny+(maxy-miny)/32;
	loop(8){
	let xpos=minx;
		loop(2){
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Sayuri - Sucker Effect - Familiar.txt",GetX,GetY,0,0,[xpos,ypos]);
		xpos=maxx;
		ypos+=(maxy-miny)/16;
		}
	}
PlaySE(SEmagics1);
}


if(frame==90){ angle=rand(0,360); speed=5; }

if(frame>=90 && speed>1.3 && time%2==0){
	if(phase==0){
		loop(40){
		if(round%2==0){ CreateShot01(GetX,GetY,speed,angle,83,10); }
		if(round%2!=0){ CreateShot01(GetX,GetY,speed,angle,84,10); }
		angle+=360/40;
		}
	angle-=360/80;
	}
	if(phase==1){
		loop(47){
		if(round%2==0){ CreateShot01(GetX,GetY,speed,angle,83,10); }
		if(round%2!=0){ CreateShot01(GetX,GetY,speed,angle,84,10); }
		angle+=360/47;
		}
	angle-=360/94;
	}
if(time%6==0){ PlaySE(SEshotm8); }
speed-=0.1;
usespell=60;
}
if(frame+90==360){
	if(GetPlayerX>minx+50 && GetPlayerX<maxx-50){
	SetMovePosition01(GetPlayerX+rand(-30,30),rand(miny+80,miny+120),1.5);
	}
	if(GetPlayerX<=minx+50){
	SetMovePosition01(GetPlayerX+rand(15,30),rand(miny+80,miny+120),1.5);
	}
	if(GetPlayerX>=maxx-50){
	SetMovePosition01(GetPlayerX-rand(15,30),rand(miny+80,miny+120),1.5);
	}
frame=0;
round++;
}

if((GetLife<=450 || GetTimer<=40) && phase==0 && speed<=1.3){
	SetColor(255,90,40);
	Concentration01(90);
	SetColor(255,255,255);
	PlaySE(SEcharge1);
	SetCommonData("SpellcardPhase",1);
	phase=1;
}


time++; frame++;
if(usespell>0){ usespell--; } if(usespell<0){ usespell++; }
SetCommonData("Boss1X",GetX); SetCommonData("Boss1Y",GetY);

#include_function "script/Functions/SpellcardName.txt";
#include_function "script/Functions/HealthBar.txt";
#include_function "script/Functions/CutIn.txt";

if(GetLife==0 && dispelled==0){ CreateEnemyFromFile("script\Functions\dispel.txt",GetX,GetY,0,0,character); dispelled=1; }
}

@BackGround{
	if(bgfade<255){ bgfade+=5; }
	SetGraphicRect(0,0,300,300);
	SetGraphicScale(1.5,1.5);
	SetTexture(BG1);
	SetAlpha(bgfade);
	SetColor(255,255,255);
	SetRenderState(ALPHA);
	SetGraphicAngle(0,0,0);
	DrawGraphic(cx,cy);
}

@DrawLoop{
	SetGraphicScale(1,1);
	SetTexture(GRboss);
	SetGraphicAngle(0,0,0);
	SetColor(255,255,255);
	SetRenderState(ALPHA);

	if(usespell>=1){ SetGraphicRect(384,outfit,512,outfit+128); }
	if(usespell<=-1){ SetGraphicRect(512,outfit,640,outfit+128); }
	if(usespell==0){
		if(GetSpeedX<=0.5 && GetSpeedX>=-0.5){ SetGraphicRect(0,outfit,128,outfit+128); }
		else if(GetSpeedX<-0.5){ SetGraphicRect(128,outfit,256,outfit+128); }
		else if(GetSpeedX>0.5){ SetGraphicRect(256,outfit,384,outfit+128); }
	}
	DrawGraphic(GetX,GetY);
}

@Finalize{
	if(GotSpellCardBonus){ SetCommonData("LastTrumpCard",10); }
	NewPointData(spellcardnumber,7);
	#include_function "script/Functions/Main Menu/SpellcardDataAndPoints.txt";
}

}